package cn.zldemo;

import android.content.Context;
import android.support.v4.view.ActionProvider;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.SubMenu;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

public class MyActionProvider extends ActionProvider {
	private Context mContext;

	public MyActionProvider(Context context) {
		super(context);
		mContext = context;
	}

	@Override
	public View onCreateActionView() {

		return null;
	}

	@Override
	public View onCreateActionView(MenuItem forItem) {
		return super.onCreateActionView(forItem);
	}

	@Override
	public boolean hasSubMenu() {
		return true;
	}

	@Override
	public void onPrepareSubMenu(SubMenu subMenu) {
		subMenu.clear();
		subMenu.add(0, 0, 0, "click me").setIcon(R.drawable.abc_text_cursor_mtrl_alpha)
				.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
					@Override
					public boolean onMenuItemClick(MenuItem item) {
						Toast.makeText(mContext, "不幸被点中了", Toast.LENGTH_SHORT).show();
						return false;
					}
				});
	}
}
